package com.qingcheng.consumer;

import com.alibaba.fastjson.JSON;
import com.qingcheng.pojo.order.OrderItem;
import com.qingcheng.service.goods.StockBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;

import java.util.List;

/**
 * @ProjectName: qingcheng_parent
 * @ClassName: BackMessageConsumer
 * @Time: 2019/7/20
 * @Author: zhou24
 * @Description:
 * @Experience:
 */
public class BackMessageConsumer implements MessageListener {

    @Autowired
    private StockBackService stockBackService;

    @Override
    public void onMessage(Message message, byte[] bytes) {
        try {
            String jsonString = new String(message.getBody());
            List<OrderItem> orderItems = JSON.parseArray(jsonString, OrderItem.class);
            System.out.println("记录订单异常日志");
            stockBackService.addList(orderItems);
        } catch (Exception e) {
            e.printStackTrace();
            //记录日志,人工干预
        }
    }
}
